from langchain_core.tools import tool
from langchain_community.utilities import SearchApiAPIWrapper
import os
os.environ["SERPAPI_API_KEY"] = "3hKP5621KiHFJ3T9R9gb9x69"
@tool("web_search",return_direct=False)
def web_search(query: str) -> str:
    """
    使用此工具搜索最新的互联网信息，当你需要获取实时信息或不确定某个事实时使用
    """
    try:
        search = SearchApiAPIWrapper
        results = search.results(query)
        return "\n\n".join({
            f"来源：{res['title']}\n内容：{res['snippet']}"
            for res in results['organic_results']
        })
    except Exception as e:
        return f"Error: {e}"
    
def get_chat_tools():
    
    tools = [
        web_search
    ]
    return tools

def get_file_tools():
    tools = [
    ]
    return tools

def get_exam_tools():
    tools=[

    ]
    return tools

def get_comment_tools():
    tools=[
        web_search
    ]
    return tools